package team.kirohuji.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import team.kirohuji.domain.Attendance;
import team.kirohuji.domain.AttendanceRecord;
import team.kirohuji.domain.SystemRole;
import team.kirohuji.domain.SystemUser;
import team.kirohuji.domain.UserInfo;
import team.kirohuji.service.AttendanceRecordService;
import team.kirohuji.service.AttendanceService;
import team.kirohuji.service.SystemUserRoleService;
import team.kirohuji.service.SystemUserService;
import team.kirohuji.service.UserInfoService;
import team.kirohuji.utils.PageUtils;
import team.kirohuji.utils.R;

/**
 * 这个Controller用户管理登录
 * 
 * @author kirohuji
 * @version 0.1
 */
@Controller
@RequestMapping("/attendance")
public class AttendanceManagerController {
	 private static final Logger logger = LoggerFactory.getLogger(AttendanceManagerController.class);
	/**
	 * @see SystemUserService
	 */
	@Resource
	private SystemUserService systemUserService;

	@Resource
	private UserInfoService userInfoService;

	@Resource
	private AttendanceService attendanceService;
	
	@Resource
	private AttendanceRecordService attendanceRecordService;
	/**
	 * @see SystemUserRoleService
	 */
	@Resource
	private SystemUserRoleService systemUserRoleService;

	/**
	 * 分页获取数据
	 * 
	 * @param page
	 *            第几页
	 * @param limit
	 *            每页最长记录数
	 * @return R {@link R}
	 */
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public R list(@RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "limit", defaultValue = "10") Integer limit) {
		Map<String, Object> map = new HashMap<>();
		map.put("offset", (page - 1) * limit);
		map.put("limit", limit);
		// 查询列表数据
		List<Attendance> List = attendanceService.queryList(map);
		int total = systemUserService.queryTotal(map);

		PageUtils pageUtil = new PageUtils(List, total, limit, page);
		return R.ok().put("page", pageUtil);

	}
}
